//
//  HistoryVC.m
//  CJRailTransport
//
//  Created by Hank on 2018/1/22.
//  Copyright © 2018年 amplity. All rights reserved.
//

#import "HistoryVC.h"
#import "HistoryCell.h"
#import "TerminalVC.h"
#import "STPickerDate.h"
#import "UIView+Expand.h"
#import "UIButton+Expand.h"

@interface HistoryVC ()<STPickerDateDelegate>

@end

@implementation HistoryVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // 设置导航栏
    [self setNavC];
    // 设置界面属性
    [self setViewAttribute];
    // 设置圆角
    [self setRadius];
    // 注册Cell
    [self registerCells];
}

#pragma mark - 导航栏
- (void)setNavC
{
    self.title = @"历史信息";
    // 设置导航栏颜色
    BasicNavigationController *nVC = (BasicNavigationController *)self.navigationController;
    nVC.themeColor = [UIColor whiteColor];
    nVC.tintColor = [UIColor darkGrayColor];
}

// 设置界面属性
- (void)setViewAttribute
{
    self.view.backgroundColor = [UIColor whiteColor];
}

// 注册Cell
- (void)registerCells
{
    UINib *nib = [UINib nibWithNibName:[HistoryCell reuseIdentifier] bundle:nil];
    [_myTableView registerNib:nib forCellReuseIdentifier:[HistoryCell reuseIdentifier]];
}

#pragma mark - Radius
// 设置圆角
- (void)setRadius
{
    [self.startDateBg radiusView:3 backgroundColor:[UIColor clearColor] borderWidth:0.5 borderColor:DefaultRadiusGray];
    [self.endDateBg radiusView:3 backgroundColor:[UIColor clearColor] borderWidth:0.5 borderColor:DefaultRadiusGray];
    [self.selectTerminalBtn radiusBtn:3 backgroundColor:DefaultGray borderWidth:0.5 borderColor:[UIColor clearColor]];
}

#pragma mark - Picker
// 显示日期选择器
- (void)showDatePicker:(NSInteger)tag
{
    STPickerDate *datePicker = [[STPickerDate alloc]init];
    [datePicker setTag:tag];
    [datePicker setDelegate:self];
    [datePicker setYearLeast:2000];
    [datePicker setYearSum:50];
    [datePicker setContentMode:STPickerContentModeBottom];
    [datePicker show];
}

#pragma mark - Action 
// 选择日期
- (IBAction)selectDateAction:(UIButton *)sender
{
    // 显示日期选择器
    [self showDatePicker:sender.tag];
}

// 查询场站 Action
- (IBAction)selectTerminalAction:(UIButton *)sender
{
    
}

#pragma mark - pickerDateDelegate
// date
-(void)pickerDate:(STPickerDate *)pickerDate year:(NSInteger)year month:(NSInteger)month day:(NSInteger)day {
    // 更新日期
    if (pickerDate.tag == 0) {
        [self.startDateBtn setTitle:[NSString stringWithFormat:@"  %ld-%@-%@", year, [self digitJudge:month], [self digitJudge:day]] forState:UIControlStateNormal];
    }else{
        [self.endDateBtn setTitle:[NSString stringWithFormat:@"  %ld-%@-%@", year, [self digitJudge:month], [self digitJudge:day]] forState:UIControlStateNormal];
    }
}
// 数字位数判断
- (NSString *)digitJudge:(NSInteger)number
{
    // 转换的字符串
    NSString *numberStr;
    
    if (number < 10) {
        numberStr = [NSString stringWithFormat:@"0%ld",number];
    }else{
        numberStr = [NSString stringWithFormat:@"%ld",number];
    }
    return numberStr;
}

#pragma mark - TableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HistoryCell *cell = [tableView dequeueReusableCellWithIdentifier:[HistoryCell reuseIdentifier] forIndexPath:indexPath];
    cell.indexPath = indexPath;
    [cell setData:nil];
    return cell;
}
#pragma mark - TableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    TerminalVC *terminalVC = [[TerminalVC alloc]init];
    [self.navigationController pushViewController:terminalVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
